package com.df.agent.plugin.impl.link;

import com.df.agent.plugin.IPlugin;
import com.df.agent.plugin.InterceptPoint;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatchers;
import net.bytebuddy.matcher.SuperTypeMatcher;

public class LinkPlugin implements IPlugin {
    @Override
    public String name() {
        return "link";
    }
    @Override
    public InterceptPoint[] buildInterceptPoint() {
        return new InterceptPoint[]{
                new InterceptPoint() {
                    @Override
                    public ElementMatcher<TypeDescription> buildTypesMatcher() {

                        return ElementMatchers.nameStartsWith("handler.")
                                .or(ElementMatchers.nameStartsWith("com.df.agent.plugin.Test"))
                                .or(ElementMatchers.nameStartsWith("common."))
                                .and(ElementMatchers.not(ElementMatchers.nameStartsWith("common.timer.")))
                                .and(ElementMatchers.not(ElementMatchers.nameStartsWith("ScriptU2GS_HeartBeat")))
                                .and(ElementMatchers.not(ElementMatchers.nameStartsWith("ScriptU2GS_HeartBeatReal")))
                                .and(ElementMatchers.not(ElementMatchers.nameStartsWith("common.heart.")));
                    }
                    @Override
                    public ElementMatcher<MethodDescription> buildMethodsMatcher() {

                        return ElementMatchers.isMethod()
                                .and(ElementMatchers.any())
                                .and(ElementMatchers.not(ElementMatchers.nameStartsWith("main")))
                                .and(ElementMatchers.not(ElementMatchers.nameStartsWith("getId")))
                                .and(ElementMatchers.not(ElementMatchers.nameStartsWith("gatherCollectCheck")))
                                .and(ElementMatchers.not(ElementMatchers.nameStartsWith("objectsTimerBuffCheck")))
                                .and(ElementMatchers.not(ElementMatchers.nameStartsWith("reliveMonster")))
                                .and(ElementMatchers.not(ElementMatchers.nameStartsWith("objectBuffTimerCheck")))
                                .and(ElementMatchers.not(ElementMatchers.nameStartsWith("buffTimerCheck")))
                                .and(ElementMatchers.not(ElementMatchers.nameStartsWith("gatherCollectCheck")))
                                .and(ElementMatchers.not(ElementMatchers.nameStartsWith("copyMapCheck")))
                                .and(ElementMatchers.not(ElementMatchers.nameStartsWith("timerTicker")))
                                .and(ElementMatchers.not(ElementMatchers.nameStartsWith("dailyActiveCheck")));
                    }
                }
        };
    }
    @Override
    public Class adviceClass() {
        return LinkAdvice.class;
    }

}
